package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.ruler.InformationService;
import com.pubinfo.passbook.engine.utils.ApplicationContextUilts;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * 历年支付
 *
 * @author zhouch
 * @date 2022/3/14 11:02
 */
@Slf4j
public class IndividualAcctPrevPayProcessor extends MedicineVariableProcessor {

    @Override
    public String getName() {
        return "历年支付";
    }

    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {

        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();

        BigDecimal individualAcctPrevPayAmount = BigDecimal.ZERO;

        for (PayInformation payInformation : payInformations) {

            BigDecimal individualAcctPrevPay = payInformation.getFundPayAmount();

            if (individualAcctPrevPay.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getSimpleName());
                individualAcctPrevPay = BigDecimal.ZERO;
            }

            individualAcctPrevPayAmount = individualAcctPrevPayAmount.add(individualAcctPrevPay);

        }

        log.info("参数处理器: {} 结果: {}", this.getClass().getSimpleName(), individualAcctPrevPayAmount);

        outputComputeMessage(individualAcctPrevPayAmount.toString());
        return individualAcctPrevPayAmount;
    }
}
